<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="utf-8">
  <title>Sign in &laquo; Admin</title>
  <link rel="stylesheet" href="../assets/vendors/bootstrap/css/bootstrap.css">
  <link rel="stylesheet" href="../assets/css/admin.css">
  <script type="text/javascript" src="/assets/jquery.1.11.js"></script>
  <style type="text/css">
  img{
    position: absolute;
    left:230px;
    top:198px;
  }
  </style>
</head>
<body>
  <div class="login">
    <form class="login-wrap">
      <img class="avatar" src="../assets/img/default.png">
      <!-- 有错误信息时展示 -->
      <!-- <div class="alert alert-danger">
        <strong>错误！</strong> 用户名或密码错误！
      </div> -->
      <div class="form-group">
        <label for="email" class="sr-only">邮箱</label>
        <input id="email" type="email" name="email" class="form-control" placeholder="邮箱" autofocus>
      </div>
      <div class="form-group">
        <label for="password" class="sr-only">密码</label>
        <input id="password" type="text" name="pwd" class="form-control" placeholder="密码">
      </div>
      <div class="form-group">
        <label for="verify" class="sr-only">验证码</label>
        <input id="verify" type="text" name="code" class="form-control" placeholder="验证码">
        <img id="code" src="verify.php">
      </div>
      <a id="dd" class="btn btn-primary btn-block" href="javascript:;">登 录</a>
    </form>
  </div>
<script type="text/javascript">
var img_obj = document.getElementById('code');
img_obj.onclick = function(){
  img_obj.src = "verify.php?"+Math.random();
}


$('.btn-primary').on('click', function(){
  //1. 获取所有表单数据
  var email = $('#email').val();
  var pwd   = $('#password').val();
  var verify= $('#verify').val();

  //2. 发送ajax请求
  var data = {email: email, pwd: pwd, verify:verify};
  $.get('check.php', data, function(msg){
    console.log(msg);
    if(msg == 1){
      alert('验证码错误');
    } else if(msg == 2){
      alert('邮箱错误');
    } else if(msg == 3){
      alert('密码错误');
    } else if(msg == 4){
      location.href = "index.php";
    }
  }) 
});
</script>
</body>
</html>
